package com.example.youjingjing.electronicbalance.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.youjingjing.electronicbalance.R;

import java.util.List;

/**
 * Created by youjingjing on 2017/7/24.
 */

public class MyRecycleviewAdapter extends RecyclerView.Adapter<MyRecycleviewAdapter.MyViewHolder> {
    private Context mContext;
    private List<String> mList;

    public MyRecycleviewAdapter(Context mContext, List<String> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //此处动态加载ViewHolder的布局文件并返回holder
        View view = LayoutInflater.from(mContext).inflate(R.layout.recycleview_item, parent, false);
        MyViewHolder holderA = new MyViewHolder(view);
        return holderA;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        //此处设置Item中view的数据
        holder.mTextView.setText(mList.get(position));
    }

    @Override
    public int getItemCount() {
        //生成的item的数量
        return mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView mTextView;
        public MyViewHolder(View itemView) {
            super(itemView);
            mTextView = (TextView) itemView.findViewById(R.id.recycle_textview);
        }
    }
}
